package sources;

public class RockPaperScissors {

	public ResultEnum play(RockPaperScissorsEnum choicePlayer1, RockPaperScissorsEnum choicePlayer2) {
		switch (choicePlayer1) {
		case ROCK:
			switch (choicePlayer2) {
			case ROCK:
				return ResultEnum.TIE;
			case PAPER:
				return ResultEnum.LOSE;
			case SCISSORS:
				return ResultEnum.WIN;
			default:
				return ResultEnum.LOSE;
			}
		case PAPER:
			switch (choicePlayer2) {
			case ROCK:
				return ResultEnum.WIN;
			case PAPER:
				return ResultEnum.TIE;
			case SCISSORS:
				return ResultEnum.LOSE;
			default:
				return ResultEnum.LOSE;
			}
		case SCISSORS:
			switch (choicePlayer2) {
			case ROCK:
				return ResultEnum.LOSE;
			case PAPER:
				return ResultEnum.WIN;
			case SCISSORS:
				return ResultEnum.TIE;
			default:
				return ResultEnum.LOSE;
			}
		default:
			return ResultEnum.LOSE;
		}
	}

	public ResultEnum play(Player player1, Player player2) {
		for (int i = 0; i < player1.getRockPaperScissorsListLength(); i++) {
			switch (play(player1.getNextChoice(), player2.getNextChoice())) {
			case WIN:
				player1.addScore();
				break;
			case TIE:
				player1.addScore();
				player2.addScore();
				break;
			case LOSE:
				player2.addScore();
				break;
			default:
				break;
			}
		}
		if (player1.getScore() > player2.getScore())
			return ResultEnum.WIN;
		else if (player1.getScore() == player2.getScore())
			return ResultEnum.TIE;
		else
			return ResultEnum.LOSE;
	}
}
